

var passwordOrCode = true;
var openTime = false;
var timeout = 60;
var openEye = false;

function getParams(key) {
    var href = window.location.href.split('?')[1];
    var list = href.split('&');
    for (var i = 0; i < list.length; i++) {
        var item = list[i].split('=');
        if (item[0] == key) {
            return item[1];
        }
    }
}

$('#login').submit(function (e) {
    $('.mask').show();
});

function checkMobile(str) {
    var re = /^1\d{10}$/
    if (re.test(str)) {
        return true;
    } else {
        alert("请输入正确手机号码");
        return false;
    }
}
function handleCode() {
    var mobile = $('input[name=mobile]').val();
    if (!mobile) {
        alert('请输入手机号码');
        return false;
    }
    if (!checkMobile(mobile)) {
        return false;
    }
    if (openTime) {
        return false
    }
    var _origin = window.location.origin;
    var domain = 'https://newbie-test-api.digitalvolvo.com';
    if ('https://newbie-test-login.digitalvolvo.com' == _origin) {
        // domain = 'https://newbie-test-api.digitalvolvo.com';
    }
    $.ajax({
        url: domain + '/mid-end-auth-center/send/sms?smsType=2&phone=' + mobile,
        success: function (res) {
            openTime = true;
            timeout = 60;
            $('.getCode').html('60S');
            var timer = setInterval(() => {
                if (timeout == 0) {
                    openTime = false;
                    timeout = 60;
                    $('.getCode').html('获取验证码');
                    clearInterval(timer);
                    return false;
                }
                timeout--;
                $('.getCode').html(timeout + 'S');
            }, 1000);
        }
    })

}

function passoerdToCode() {
    passwordOrCode = !passwordOrCode;

    if (!passwordOrCode) {
        $('.loginType').html('密码登录');
        $('.passwordLogin').hide();
        $('.codeLogin').show();
    } else {
        $('.loginType').html('验证码登录');
        $('.passwordLogin').show();
        $('.codeLogin').hide();
    }


}
function handleEye() {
    $('.eye').toggleClass('icon-eye3');
    openEye = !openEye;
    if (openEye) {
        $('#password').attr('type', 'text')
    } else {
        $('#password').attr('type', 'password')
    }
}

$(function () {
   $("#username").keyup(function () {
      if($(this).val().length>0){
          $(".input span.username").addClass("no-empety")
      }else {
          $(".input span.username").removeClass("no-empety")
      }
   })
    $("#password").keyup(function () {
        if($(this).val().length>0){
            $(".input span.password").addClass("no-empety")
        }else {
            $(".input span.password").removeClass("no-empety")
        }
    })
})